/**
 * @file        interface.hpp
 * @brief       gtdshell command line interface handling.
 *
 * @author      Emre Turkay <emreturkay at gmail>
 * @date        May.31.2008
 */

#ifndef _INTERFACE_HPP_
#define _INTERFACE_HPP_

#include <boost/function.hpp>

#include <map>
#include <vector>
#include <string>
#include <iostream>

struct action_info
{
    typedef std::vector<std::string> args_type;
    typedef boost::function<void(const args_type&)> function_type;

    action_info() { }
    action_info(function_type f, const std::string& desc = "");

    void operator()(const args_type& args);

    const std::string& description() const { return description_; }

private:
    function_type function_;
    std::string description_;
};

struct interface
{
    typedef action_info::args_type args_type;
    typedef action_info::function_type function_type;
    typedef std::map<std::string, action_info> actions_type;

    void command(const std::string& text, function_type action,
                 const std::string& description = "");

    bool process();

    void help();

    std::ostream& out();

    std::istream& in();

private:
    actions_type actions_;
};

#endif // _INTERFACE_HPP_
